package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.User;
import po.Winner;
import service.WinnerService;



@Controller
public class winnerController {
	
	// 依赖注入
	@Autowired
	private WinnerService winnerService;	
	@RequestMapping(value = "/winner/getWinner.action")
	public String list( Model model) {
		List<Winner> winnerlist = winnerService.getWinnerList();
		model.addAttribute("winnerlist", winnerlist);	
		return "winner_list";

	}
	@RequestMapping("/winner/delWinner.action")
	public String winnerDelete(Integer winnerid) {
		int rows = winnerService.deleteWinner(winnerid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/winner/getWinner.action";
	}
	@RequestMapping("/winner/addWinner.action")
	public String winnerAdd(Winner winner) {
		int rows = winnerService.addWinner(winner);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/course/getCourse.action";
	}
	
	@RequestMapping(value ="/winner/getwinnerId.action")
	@ResponseBody
	public Winner getCourseId(Integer id) {
		Winner data = winnerService.getWinnerId(id);
		return data;
   }  
	
	@RequestMapping(value ="/winner/updateWinner.action")
	@ResponseBody
	public String updateWinner(Winner winner) {
		int row = winnerService.updateWinner(winner);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   }
	@RequestMapping(value = "/winner/findAll.action")
	public String listAll(String data,Model model) {	
		List<Winner> winnerlist = winnerService.findList(data);
		model.addAttribute("winnerlist", winnerlist);	
		return "winner_list";
	}
}
